package chatclient;

import java.io.IOException;
import java.io.OutputStream;
import javax.swing.JTextArea;

/**
 * Class used to direct stream output to JTextArea object
 * @author Ciaran Liedeman
 * @version 0.1
 */
public class TextAreaStream extends OutputStream {

    JTextArea textArea;

    private TextAreaStream(){

    }

    TextAreaStream(JTextArea textArea){
        this.textArea = textArea;
    }

    @Override
    public void write(final int b) throws IOException {
        textArea.append(String.valueOf((char) b));
    }

    @Override
    public void write(byte[] b, int off, int len) throws IOException {
        textArea.append(new String(b, off, len));
    }

    @Override
    public void write(byte[] b) throws IOException {
        write(b, 0, b.length);
    }
}
